#!/usr/bin/python2.4
#
# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A special handler file for rendering template files of various types."""

# AppEngine
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

# Python
import logging
import os


class Css(webapp.RequestHandler):
  def get(self, args=None):
    self.response.headers['Content-Type'] = 'text/css'
    request = os.path.join(self.request.path_info[1:])
    if os.path.exists(request):
        path = template.render(request, {})
    else:
        self.error(404)
        path = ''
    self.response.out.write(path)


class Img(webapp.RequestHandler):
  def get(self, args=None):
    self.response.headers['Content-Type'] = 'image/*'
    request = os.path.join(self.request.path_info[1:])
    if os.path.exists(request):
        path = template.render(request, {})
    else:
        self.error(404)
        path = ''
    self.response.out.write(path)


class Js(webapp.RequestHandler):
  def get(self, args=None):
    self.response.headers['Content-Type'] = 'text/javascript'
    request = os.path.join(self.request.path_info[1:])
    if os.path.exists(request):
        path = template.render(request, {})
    else:
        self.error(404)
        path = ''
    self.response.out.write(path)